package com.lh.service.impl;

import com.lh.client.EduClient;
import com.lh.client.UcenterClient;
import com.lh.commonutils.ordervo.CourseWebVoOrder;
import com.lh.commonutils.ordervo.UcenterMemberOrder;
import com.lh.entity.TOrder;
import com.lh.dao.TOrderMapper;
import com.lh.service.ITOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lh.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author lh
 * @since 2021-06-16
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService {


    @Autowired
    private EduClient eduClient;

    @Autowired
    private UcenterClient ucenterClient;

//    生成订单的方法
    @Override
    public String creatOrders(String courseId, String memberIdByJwtToken) {
//        通过远程调用根据用户id获取用户信息
        UcenterMemberOrder memberOrder = ucenterClient.getUserInfoOrser(courseId);

//        通过远程调用根据课程id获取课程信息
        CourseWebVoOrder courseInfoOrder = eduClient.getCourseInfoOrder(courseId);
//       创建order对象  设置需要的数据

        TOrder order = new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfoOrder.getTitle());
        order.setCourseCover(courseInfoOrder.getCover());
        order.setTeacherName("test");
        order.setTotalFee(courseInfoOrder.getPrice());
        order.setMemberId(memberIdByJwtToken);
        order.setMobile(memberOrder.getMobile());
        order.setNickname(memberOrder.getNickname());
        order.setStatus(0);//支付状态
        order.setPayType(1);//支付类型
        baseMapper.insert(order);

//                返回订单号
        return order.getOrderNo();
    }
}
